//
//  LHRecommendCityHomePageView.m
//  Knight_Tour
//
//  Created by 庞魁 on 15-5-15.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHRecommendCityHomePageView.h"
#import "UIImageView+WebCache.h"
#import "LHRecommendCityModel.h"

@interface LHRecommendCityHomePageView ()

@property (nonatomic, retain) UIImageView *cityPicture;
@property (nonatomic, retain) UILabel *cityName;
@property (nonatomic, retain) UIButton *collectionButton;
@property (nonatomic, retain) UILabel *guideLabel;
@property (nonatomic, retain) UILabel *upCrossLabel;
@property (nonatomic, retain) UILabel *downCrossLabel;
@property (nonatomic, retain) UILabel *sightLabel;
@property (nonatomic, retain) UILabel *hotelLabel;
@property (nonatomic, retain) UILabel *resLabel;
@property (nonatomic, retain) UILabel *popularLabel;

@end

@implementation LHRecommendCityHomePageView

- (void)dealloc
{
    [_cityName release];
    [_cityPicture release];
    [_collectionButton release];
    [_guideLabel release];
    [_upCrossLabel release];
    [_downCrossLabel release];
    [_recommendRes release];
    [_recommendSight release];
    [_recommendHotel release];
    [_popularLabel release];
    
    [super dealloc];
}

// 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self createRecommendCityHomePageView];
    }
    
    
    return self;
}

/**
 *  创建推荐城市主页view视图
 */
- (void)createRecommendCityHomePageView
{

    
    // 创建城市相框
    self.cityPicture = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 3 * 2)];
    
    _cityPicture.backgroundColor = [UIColor colorWithRed:0.380 green:0.225 blue:0.068 alpha:1.000];
    
    [self addSubview:_cityPicture];
    
    [_cityPicture release];
    
    // 创建城市名和省名标签
    self.cityName = [[UILabel alloc] initWithFrame:CGRectMake(15, _cityPicture.frame.origin.y + self.frame.size.height / 3 * 2, 60, 30)];
    
    [self addSubview:_cityName];
    
    [_cityName setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
    
    [_cityName release];
    
    
    // 收藏按钮
    self.collectionButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    _collectionButton.frame = CGRectMake(_cityPicture.frame.size.width - 50, _cityPicture.frame.origin.y + self.frame.size.height / 3 * 2 + 10, 40, 30);
    
    
    _collectionButton.backgroundColor = [UIColor colorWithRed:0.871 green:0.962 blue:0.965 alpha:1.000];
    
    [self addSubview:_collectionButton];
    
    
    // 分类指南
    self.guideLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, _collectionButton.frame.origin.y + 50 , 40, 15)];
    
//    _guideLabel.backgroundColor = [UIColor colorWithRed:0.909 green:0.000 blue:0.283 alpha:1.000];
    
    _guideLabel.text = @"分类指南";
    
    [_guideLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:10]];
    
    [_guideLabel setTextColor:[UIColor blackColor]];
    
    [self addSubview:_guideLabel];
    
    [_guideLabel release];
    
    // 上横线
    self.upCrossLabel = [[UILabel alloc] initWithFrame:CGRectMake(_guideLabel.frame.origin.x + 50, _collectionButton.frame.origin.y + 55, self.frame.size.width - 55, 2)];
    
    _upCrossLabel.backgroundColor = [UIColor colorWithRed:0.760 green:0.759 blue:0.936 alpha:1.000];
    
    [self addSubview:_upCrossLabel];
    
    [_upCrossLabel release];
    
// 推荐功能Button
    // 推荐景点
    self.recommendSight = [UIButton buttonWithType:UIButtonTypeSystem];
    
    [_recommendSight setBackgroundImage:[UIImage imageNamed:@"jingdian"] forState:UIControlStateNormal];
    
    _recommendSight.frame = CGRectMake(self.frame.size.width / 6 + 10, _upCrossLabel.frame.origin.y + 20, self.frame.size.width / 8, self.frame.size.width / 8);
    
    _recommendSight.layer.cornerRadius = 20;
    _recommendSight.clipsToBounds = YES;
    
    [self addSubview:_recommendSight];
    
    // 推荐旅馆
    self.recommendHotel = [UIButton buttonWithType:UIButtonTypeSystem];
    
   [_recommendHotel setBackgroundImage:[UIImage imageNamed:@"jiudian"] forState:UIControlStateNormal];
    
    _recommendHotel.frame = CGRectMake(_recommendSight.frame.origin.x + self.frame.size.width / 6 + 20, _upCrossLabel.frame.origin.y + 20, self.frame.size.width / 8, self.frame.size.width / 8);
    
    _recommendHotel.layer.cornerRadius = 20;
    _recommendHotel.clipsToBounds = YES;
    
    [self addSubview:_recommendHotel];
    
    
    // 推荐餐馆
    self.recommendRes = [UIButton buttonWithType:UIButtonTypeSystem];
    
    [_recommendRes setBackgroundImage:[UIImage imageNamed:@"meishi"] forState:UIControlStateNormal];
    
    _recommendRes.frame = CGRectMake(_recommendHotel.frame.origin.x + self.frame.size.width / 6 + 20, _upCrossLabel.frame.origin.y + 20, self.frame.size.width / 8, self.frame.size.width /8);
    
    _recommendRes.layer.cornerRadius = 20;
    _recommendRes.clipsToBounds = YES;
    
    [self addSubview:_recommendRes];
    
    
    // 每个button下的label
    self.sightLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 6 - 5 + 10, _recommendSight.frame.origin.y + self.frame.size.width / 7 + 5, self.frame.size.width / 7, 20)];

    [self addSubview:_sightLabel];
    
    _sightLabel.text = @"景点";
    
    [_sightLabel setTextAlignment:NSTextAlignmentCenter];
    
    [_sightLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
    
    [_sightLabel setTextColor:[UIColor blackColor]];
    
    [_sightLabel release];
    
    
    self.hotelLabel = [[UILabel alloc] initWithFrame:CGRectMake(_recommendSight.frame.origin.x + self.frame.size.width / 6 - 5 + 20, _recommendHotel.frame.origin.y + self.frame.size.width / 7 + 5, self.frame.size.width / 7, 20)];
    
    [self addSubview:_hotelLabel];
    
    _hotelLabel.text = @"旅馆";
    
    [_hotelLabel setTextAlignment:NSTextAlignmentCenter];
    
    [_hotelLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
    
    [_hotelLabel setTextColor:[UIColor blackColor]];
    
    [_hotelLabel release];
    
    self.resLabel = [[UILabel alloc] initWithFrame:CGRectMake(_recommendHotel.frame.origin.x + self.frame.size.width / 6 - 5 + 20, _recommendRes.frame.origin.y + self.frame.size.width / 7 + 5, self.frame.size.width / 7, 20)];
    
    [self addSubview:_resLabel];
    
    _resLabel.text = @"美食";
    
    [_resLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11]];
    
    [_resLabel setTextAlignment:NSTextAlignmentCenter];
    
    [_resLabel setTextColor:[UIColor blackColor]];
    
    [_resLabel release];
    
    
    
    // 下横线
    
    self.downCrossLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _sightLabel.frame.origin.y + _sightLabel.frame.size.height + 10, self.frame.size.width, 2)];
    
    _downCrossLabel.backgroundColor = [UIColor colorWithRed:0.760 green:0.759 blue:0.936 alpha:1.000];
    
    [self addSubview:_downCrossLabel];
    
    [_downCrossLabel release];
    
    // 创建热门目的地label
    
    self.popularLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, _downCrossLabel.frame.origin.y + 12, 70, 30)];
    
    [self addSubview:_popularLabel];
    
    _popularLabel.text = @"热门目的地";
    
    [_popularLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
    
    [_popularLabel setTextColor:[UIColor blackColor]];
    
    [_popularLabel setTextAlignment:NSTextAlignmentCenter];
    
    [_popularLabel release];
    
}

// 重写setter方法
- (void)setCity_arr:(LHRecommendCityModel *)city_arr
{
    if (_city_arr != city_arr) {
        
        [_city_arr release];
        
        _city_arr = [city_arr retain];
        
    }
    
    [_cityPicture sd_setImageWithURL:[NSURL URLWithString:city_arr.cover] placeholderImage:[UIImage imageNamed:@"word4"]];
    
    _cityName.text = city_arr.name;
    
}










/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
